package com.demo.interceptor;

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;

public class MyAuthenticationInterceptor implements Interceptor {

	/**
	 * 
	 */
	private static final long serialVersionUID = -8157022133847137996L;

	@Override
	public void destroy() {
		System.out.println("in destroy mehtod");
	}

	@Override
	public void init() {
		System.out.println("in intercpetor init method");
	}

	@Override
	public String intercept(ActionInvocation invocation) throws Exception {
	    
		System.out.println(" before invoke :intercpt method");
		         
		 HttpSession session=ServletActionContext.getRequest().getSession();
		  
		  if(null==session.getAttribute("user")){
			  return  Action.LOGIN;
		  }

		 invocation.invoke(); // here next subsequent interceptor execution will be started..
	     System.out.println("after invoke :  in intercept method");
	    
		return null;
	}

	
}
